<?php

namespace Yxchat\Model;

use Common\Model\BaseModel;
use Common\Model\ModelException;

class YxGroupModel extends BaseModel {

    protected $_auto = [
        ['create_time', 'time', self::MODEL_INSERT, 'function'],
        ['update_time', 'time', self::MODEL_BOTH, 'function'],
    ];
    protected $_validate = [];
    protected $_scope = [
        'valid' => [
            'where' => ['closed' => 0]
        ]
    ];
    
    /*
     * 聊吧im群信息
     */

    public function storeGroup($param) {
        $param['create_time'] = time();
        if (!empty($param['icon'])) {
            $param['icon'] = uploadBase64toOss($param['icon'], 'group_' . $param['group_id']);
        }
        $YxGroup = D('YxGroup');
        $res = $YxGroup->where(['group_id' => $param['group_id']])->find();
        if (!empty($res)) {
            $YxGroup->save($param);
        } else {
            $YxGroup->add($param);
        }
        return true;
    }

    protected function _after_find(&$record, $options) {
        
    }

    protected function _after_select(&$records, $options) {
        
    }

}
